package com.tx.service.impl;

import com.tx.dao.ReplyDao;
import com.tx.entity.Comment;
import com.tx.entity.Reply;
import com.tx.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ReplyServiceImpl implements ReplyService {
    //注入博客回复数据持久层接口
    @Autowired
    private ReplyDao replyDao;

    /* *
     * @description: 新增博客回复
     * @author tcx
     * @date 2020/04/30
     * @param reply
     * @return void
     */
    public Integer add(Reply reply) {
        //回复时间
        reply.setrCreateTime(new Date());
        return replyDao.insert(reply);
    }
    /* *
     * @description: 获取所有博客下所有评论回复
     * @author tcx
     * @date 2020/04/30
     * @param
     * @return java.util.List<com.tx.entity.Reply>
     */
    public List<Reply> getReplyByBlog(Integer bId) {
        return replyDao.selectReplyByBlog(bId);
    }

    public List<Reply> getAll(Map<String,Object> map) {
        return replyDao.selectAll(map);
    }
    //总数
    public Integer getTotal(Map<String, Object> map) {
        return replyDao.selectAllCount(map);
    }
    //删除回复
    public Integer remove(Integer rId) {
        return replyDao.delete(rId);
    }
    //编辑回复
    public Integer edit(Reply reply) {
        return replyDao.update(reply);
    }

    public Integer getCountState(Map<String,Object> map) {
        Integer count = replyDao.selectReplyCountByUser(map);
        if(count!=null&&count>0)
            return count;
        return 0;
    }
    public Integer editReplyState(Integer rId) {
        return replyDao.updateSate(rId);
    }
}
